package de.zainodis.authorlist.model;

import java.util.Arrays;
import java.util.Collection;

import de.zainodis.commons.model.CurrencyAmount;

public abstract class AuthorsCreation {

   private String title;
   private Collection<String> authors;
   private String isbn;
   private CurrencyAmount price;

   public String getTitle() {
	 return title;
   }

   public String getIsbn() {
	 return isbn != null ? String.format("ISBN %s", isbn) : null;
   }

   public String getPrice() {
	 if (price == null) {
	    price = new CurrencyAmount("0");
	 }
	 return price.format();
   }

   public Collection<String> getAuthors() {
	 return authors;
   }

   public void setTitle(String title) {
	 this.title = title;
   }

   public void setAuthors(Collection<String> authors) {
	 this.authors = authors;
   }

   public void setAuthors(String[] authors) {
	 this.authors = Arrays.asList(authors);
   }

   public void setIsbn(String isbn) {
	 this.isbn = isbn;
   }

   public void setPrice(String price) {
	 /*
	  * We convert the value to double here, as it is provided in double
	  * format, if we'd directly convert to a currency, the values for German
	  * for instance would come out wrong, as 9.45 is in fact 9450 in countries
	  * where the dot is a separator for thousands.
	  */
	 this.price = new CurrencyAmount(Double.parseDouble(price));
   }

   public abstract int getIcon();

}
